package com.example.exceltosqlite.ui.sqldao;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;

import com.example.exceltosqlite.entity.SqliteFileEntity;
import com.example.exceltosqlite.entity.SqliteFileNumberEntity;

import java.util.ArrayList;
import java.util.List;

public class SpinnerFileAdapter extends BaseAdapter {
    private Context context;

    public SpinnerFileAdapter(Context context) {
        this.context = context;
    }

    private List<SqliteFileEntity> items = new ArrayList<>();

    public Context getContext() {
        return context;
    }

    public void setContext(Context context) {
        this.context = context;
    }

    public List<SqliteFileEntity> getItems() {
        return items;
    }

    public void setItems(List<SqliteFileEntity> items) {
        if(null == items){
            items.clear();
        }else{
            this.items = items;
        }
        notifyDataSetChanged();
    }

    @Override
    public int getCount() {
        return items.size();
    }

    @Override
    public Object getItem(int position) {
        return items.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int p, View v, ViewGroup parent) {
        SpinnerFileItemview spinnerFileItemview;
        if(null == v){
            spinnerFileItemview = new SpinnerFileItemview(context);
        }else{
            spinnerFileItemview = (SpinnerFileItemview) v;
        }
        spinnerFileItemview.bind(items.get(p));
        return spinnerFileItemview;
    }
}
